package com.production.CoursePlatform.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.production.CoursePlatform.entity.Comment;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CommentMapper extends BaseMapper<Comment> {

    // 创建新的评论，无需cmtID，自动生成cmtID
    @Insert("INSERT INTO comment (s_id, d_id, cmt_content, cmt_time) " +
            "VALUES (#{sID}, #{dID}, #{cmtContent}, #{cmtTime})")
    void insertComment(Comment comment);

    // 根据cmtID查找评论
    @Select("SELECT * FROM comment WHERE d_id = #{dID}")
    List<Comment> selectByCmtId(@Param("dID") int dID);

    // 删除指定cmtID的评论
    @Delete("DELETE FROM comment WHERE cmt_id = #{cmtID}")
    int deleteByCmtId(@Param("cmtID") int cmtID);

    // 更新评论内容
    @Update("UPDATE comment SET s_id = #{sID}, d_id = #{dID}, cmt_content = #{cmtContent}, " +
            "cmt_likes = #{cmtLikes}, cmt_replies = #{cmtReplies} WHERE cmt_id = #{cmtID}")
    int updateComment(Comment comment);
}
